/*
 * Copyright 2018 datagear.tech
 *
 * Licensed under the LGPLv3 license:
 * http://www.gnu.org/licenses/lgpl-3.0.html
 */

package org.datagear.management.service.impl;

import java.util.Date;
import java.util.Map;

import org.apache.ibatis.session.SqlSessionFactory;
import org.datagear.management.domain.HtmlContentDashboardEntity;
import org.datagear.management.service.HtmlContentDashboardEntityService;
import org.datagear.management.util.dialect.MbSqlDialect;

import com.google.common.collect.Maps;

/**
 * {@linkplain HtmlContentDashboardEntityService}实现类。
 * 
 * @author datagear@163.com
 */
public class HtmlContentDashboardEntityServiceImpl extends AbstractMybatisEntityService<String, HtmlContentDashboardEntity>
		implements HtmlContentDashboardEntityService {
	protected static final String SQL_NAMESPACE = HtmlContentDashboardEntity.class.getName();

	public HtmlContentDashboardEntityServiceImpl() {
		super();
	}

	public HtmlContentDashboardEntityServiceImpl(SqlSessionFactory sqlSessionFactory, MbSqlDialect mbSqlDialect) {
		super(sqlSessionFactory, mbSqlDialect);
	}

	@Override
	protected String getSqlNamespace() {
		return SQL_NAMESPACE;
	}

	@Override
	public HtmlContentDashboardEntity getById(String id, String template) {
		Map<String, Object> params = Maps.newHashMap();
		params.put("id", id);
		params.put("template", template);
		return selectOneMybatis("getById", params);
	}

	@Override
	public boolean deleteById(String id, String template) {
		Map<String, Object> params = Maps.newHashMap();
		params.put("id", id);
		params.put("template", template);
		return (deleteMybatis("deleteById", params) > 0);
	}

	@Override
	public boolean saveOrUpdate(String id, String template, String content) {
		Map<String, Object> params = Maps.newHashMap();
		params.put("id", id);
		params.put("template", template);
		params.put("content", content);
		params.put("createTime", new Date());
		return (updateMybatis("replace", params) > 0);
	}
}
